#include "reel.h"

#include <iostream>
using namespace std;

Real::Real(double val) : NonComplexNumber(REAL){
        this->val = val;
this->type = REAL;
}

Real::Real(const Integer& i) : NonComplexNumber(REAL){

this->type = REAL;
        this->val = i.getVal();
}

Real::Real(const Fraction& f) : NonComplexNumber(REAL){

this->type = REAL;
        this->val = (double)f.getNum()/(double)f.getDen();
}

Constante* Real::operator+(const Constante& c)const{
        switch(c.getType()){
                case Constante::INTEGER:
        return *this+Real(static_cast<const Integer&>(c));
                break;
                case Constante::RATIONNAL:
        return *this+Real(static_cast<const Fraction&>(c));
                break;
                case Constante::REAL:
        return new Real(this->val + static_cast<const Real&>(c).val);//*this+static_cast<const Real&>(c);
                break;
        }
}

Constante* Real::operator*(const Constante& c)const{
        switch(c.getType()){
                case Constante::INTEGER:
        return *this*Real(static_cast<const Integer&>(c));
                break;
                case Constante::RATIONNAL:
        return *this*Real(static_cast<const Fraction&>(c));
                break;
                case Constante::REAL:
        return new Real(this->val * static_cast<const Real&>(c).val);//*this+static_cast<const Real&>(c);
                break;
        }
}
Constante* Real::operator-(const Constante& c)const{
        switch(c.getType()){
                case Constante::INTEGER:
        return *this-Real(static_cast<const Integer&>(c));
                break;
                case Constante::RATIONNAL:
        return *this-Real(static_cast<const Fraction&>(c));
                break;
                case Constante::REAL:
        return new Real(this->val - static_cast<const Real&>(c).val);//*this+static_cast<const Real&>(c);
                break;
        }
}

Constante* Real::operator/(const Constante& c)const{
        switch(c.getType()){
                case Constante::INTEGER:
        return *this/Real(static_cast<const Integer&>(c));
                break;
                case Constante::RATIONNAL:
        return *this/Real(static_cast<const Fraction&>(c));
                break;
                case Constante::REAL:
        return new Real(this->val / static_cast<const Real&>(c).val);//*this+static_cast<const Real&>(c);
                break;
        }
}

Constante* Real::operator-()const{
        return new Real(-this->val);
}
